package org.dandsoft.blackbox.laboratory.tests.replace;

import org.dandsoft.blackbox.SignalId;
import org.dandsoft.blackbox.Time;

import java.util.Set;
import java.util.HashSet;

/**
 * @author Vilyuzhanin Denis (Fin)
 */
public class Trigger {
    private SignalId signalId;
    private Set<SignalId> image = new HashSet<SignalId>();
    private int foundSignals;
    private Time time;
    private int useful;

    public void init(Time time) {
        this.time = time;
        foundSignals = 0;
    }

    public int getUseful() {
        return useful;
    }

    public void setUseful(int useful) {
        this.useful = useful;
    }

    public void incrementUseful() {
        this.useful++;
    }

    public SignalId getSignalId() {
        return signalId;
    }

    public void setSignalId(SignalId signalId) {
        this.signalId = signalId;
    }

    public Set<SignalId> getImage() {
        return image;
    }

    public boolean check(Time time, SignalId signalId) {
        if (!time.equals(this.time)) {
            init(time);
        }

        if (image.contains(signalId)) {
            foundSignals++;
            return true;
        } else {
            return false;
        }
    }

    public boolean isFound(Time time) {
        if (!time.equals(this.time)) {
            init(time);
        }
        return foundSignals == image.size();
    }

}
